//
//  NSDictionary+NSNull.m
//  Mahjong
//
//  Created by 饶首建 on 17/6/27.
//  Copyright © 2017年 com.ikamobile.com. All rights reserved.
//

#import "NSDictionary+NSNull.h"

@implementation NSDictionary (NSNull)

+ (id)recursionResultJson4NullclassToNullstring:(id)obj{
    if ([obj isKindOfClass:[NSDictionary class]]) {
        NSMutableDictionary *mutableDict = [[NSMutableDictionary alloc]initWithDictionary:[obj copy]];
        for (NSString *key in obj) {
            if ([mutableDict[key] isKindOfClass:[NSDictionary class]] || [mutableDict[key] isKindOfClass:[NSArray class]]) {
                mutableDict[key] = [self recursionResultJson4NullclassToNullstring:mutableDict[key]];
            }else if ([mutableDict[key] isKindOfClass:[NSNull class]]) {
                mutableDict[key] = @"";
            }
        }
        return mutableDict;
    }else if ([obj isKindOfClass:[NSArray class]]){
        NSMutableArray *mutableArr = [[NSMutableArray alloc]initWithArray:[obj copy]];
        for (int i = 0; i < mutableArr.count; i++) {
            id arrObj = mutableArr[i];
            if ([arrObj isKindOfClass:[NSDictionary class]] || [arrObj isKindOfClass:[NSArray class]]) {
                [mutableArr replaceObjectAtIndex:i withObject:[self recursionResultJson4NullclassToNullstring:arrObj]];
            }else if ([arrObj isKindOfClass:[NSNull class]]) {
                [mutableArr replaceObjectAtIndex:i withObject:@""];
            }
        }
        return mutableArr;
    }else if([obj isKindOfClass:[NSNull class]]){
        return @"";
    }else{
        return obj;
    }
}

@end
